package com.geek.water.config;
import com.geek.water.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author chenmin
 * @desc TODO
 * @date 2025/7/24
 *
 *  * http://localhost:8080/swagger-ui.html
 *  * http://localhost:8080/doc.html
 */
//@Configuration(proxyBeanMethods = false)
public class WebConfig {
    //@Bean
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            //设置本地图片服务器路径
            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler("/pic/**").addResourceLocations("file:\\D:\\Water\\pictures\\");
            }

            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(new LoginInterceptor())
                        .addPathPatterns("/**")
                        .excludePathPatterns(
                                "/admin/auth/**",            // 登录、注册等不拦截
                                "/swagger-ui.html",          // Swagger 主页面
                                "/swagger-resources/**",     // Swagger 资源路径
                                "/v2/api-docs",              // Swagger 文档接口
                                "/webjars/**",               // Swagger 静态资源
                                "/v3/api-docs",              // OpenAPI v3（如有）
                                "/doc.html",                 // Knife4j 页面（如用的是 Knife4j）
                                "/favicon.ico"  ,             // 网站图标
                                "/admin/device/**",
                                "/admin/device",
                                "/pic/**",
                                "/admin/area/**",
                                "/admin/area",
                                "/admin/site/**",
                                "/admin/site",
                                "/admin/customer/**",
                                "/admin/customer",
                                "/admin/water-price-tier/**", // 阶梯水费配置接口
                                "/admin/global-water-price-tier/**", // 全局阶梯水费配置接口
                                "/error",
                                "/admin/invoice/**",
                                "/csrf",
                                "/admin/invoice/apply"

                        );
            }
        };
    }
}
